package cz.myslivec.slovicka.vocimport.csvparse;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;

import com.Ostermiller.util.CSVParser;

import cz.myslivec.slovicka.entity.Vocable;

@Name("vocableParser")
@AutoCreate
public class VocableParser extends ParserTemplate<Vocable> {
	
	@Logger
	private Log log;
	
	@Override
	protected Vocable processLine(CSVParser csvp, String[] line) {
		if((line == null) || (line.length == 0)) {
			return null;
		}
		Vocable result = new Vocable();
		if(line.length > 1) {
			result.setStr1(line[0].trim());
		}
		if(line.length > 2) {
			result.setStr2(line[1].trim());
		}
		if(line.length > 3) {
			result.setStr3(line[2].trim());
		}
		if(line.length > 4) {
			result.setStr4(line[3].trim());
		}
		
		if(line.length > 5) {
			log.warn("Line '{0}' has to many ({1}) parts!!!", line.toString(), line.length);
		}
		
		return result;
	}
}
